package day1127_1;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class D3 {
    public static void main(String[] args)  throws  Exception  {
        Class.forName("com.mysql.cj.jdbc.Driver");//1.
        Connection  conn= DriverManager.getConnection("jdbc:mysql://localhost:3306/big1?serverTimezone=GMT%2B8&useSSL=false",
                "root","root");//2.
        PreparedStatement  pstmt=conn.prepareStatement("select * from stu where id=?");//3.
        pstmt.setInt(1,1);//给第一个问号设置一个  参数值1
        ResultSet  rs=pstmt.executeQuery();//4.执行查询语句  (结果封装到ResultSet对象中)

        while(rs.next()){//5.获取查询结果
            System.out.println(rs.getInt(1));
            System.out.println(rs.getString(2));
        }

        rs.close();//6.关闭数据库连接
    }
}






